/*
 *
 *  * Copyright (c) 2016. For Intelligent Group.
 *
 */
package com.intelligent.ispc.client.core.view.analysis.grr.render;

import com.intelligent.ispc.client.core.modal.grr.ItemDetailTableModel;
import com.intelligent.ispc.client.utils.Colur;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.Component;

/**
 * Created by cherry on 16/9/6.
 */
public class ItemDetailRender extends DefaultTableCellRenderer {
    private ItemDetailTableModel model;
    private int trialCount;
    private int rowCount;

    /**
     * item detail render constructor one parameter
     *
     * @param table selected table
     */
    public ItemDetailRender(JTable table) {

        model = (ItemDetailTableModel) table.getModel();
        trialCount = model.getTrialCount();
        rowCount = model.getRowCount();
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        int reminder = row % (trialCount + 2);
        boolean flag = true;

        if ((row == rowCount - 2) || (row == rowCount - 1)) {
            setBackground(Colur.DEGRAY);
            flag = false;
        }

        if ((reminder == trialCount) || (reminder == trialCount + 1)) {
            setBackground(Colur.GRAY);
            flag = false;
        }

        if (flag) {
            setBackground(Colur.WHITE);
        }

        setHorizontalAlignment(CENTER);
        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }
}
